import './env'
import './profile'
import './env.scss'
import './profile.scss'



// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.


// vue模块：开始
import Vue from 'vue'
window.Vue = Vue
Vue.config.productionTip = false


// import {NavStackPlugin} from "vue-nav-stack";
// Vue.use(NavStackPlugin,"NavStack");
import {KeepAliveExtendPlugin} from "vue-nav-stack";
Vue.use(KeepAliveExtendPlugin);




import createTopSpinnerDisplaySwitch from ":components/createTopSpinnerDisplaySwitch"
shareInst.topSpinner = createTopSpinnerDisplaySwitch("dots");

//页面切换时关闭loading：开始
import listenVueSwitch from 'listen-vue-switch'

listenVueSwitch.parentNames = "keep-alive";
listenVueSwitch.deactivate = function (alive,vueInst,parentInst) {
  if (shareInst.app && shareInst.app.$vux) {
    shareInst.app.$vux.loading.hide();
  }
};

listenVueSwitch();

//页面切换时关闭loading：结束


// 导入全局组件 : 开始
import {expandXHeader} from "xheader-extend";

const XHeader = expandXHeader({
  updateNavBarOptions:function(navBarOptions,headerInst){
    shareInst.client.updateNavBarOptions(navBarOptions);
  },
  hide:function(){
    return !shareInst.client.showWebNavBar
  }
});

import customViewBox from "custom-viewbox";
import {createAutoDisplayHeaderDataHandler,createCopyrightDataHandler,createConfigDataForSlotsOfViewBoxDataHandler,createAutoSetBodyPaddingForViewBoxDataHandler} from  "viewbox-data-handler";

import { LoadingPlugin, ToastPlugin} from 'vux'





let autoDisplayHeader = createAutoDisplayHeaderDataHandler({
  navBarHeight:"46px",
  hide:function(){
    return !shareInst.client.showWebNavBar
  }
});

import Copyright from ':components/Copyright'
let copyrightTempDataHandle = createCopyrightDataHandler({
  showCopyright:true,
  copyright:Copyright
});



/**
 * 当 ByViewBox 的 header 和 bottom 都只有一个时，给 ByViewBox 的 header 和 bottom slots 配置 模板数据
 */
const configTempDataForSlotsOfViewBox = createConfigDataForSlotsOfViewBoxDataHandler({
  header:{class:"view-box-header-slot"},
  bottom:{class:"view-box-bottom-slot"},
});


/**
 * autoSetBodyPaddingForViewBox 作用：
 * 当 有 header 且 没有设置 bodyPaddingTop 时，会自动设置 ViewBox 的 bodyPaddingTop 为 paddingTop
 * 当 有 bottom 且 没有设置 bodyPaddingBottom 时，会自动设置 ViewBox 的 bodyPaddingBottom 为 paddingBottom
 */
const autoSetBodyPaddingForViewBox = createAutoSetBodyPaddingForViewBoxDataHandler({
  paddingTop:"47px",
  paddingBottom:"50px"
});


let ViewBox = customViewBox([autoDisplayHeader,copyrightTempDataHandle,configTempDataForSlotsOfViewBox,autoSetBodyPaddingForViewBox]);




Vue.usePlugins([LoadingPlugin, ToastPlugin]);
Vue.regComponents({XHeader, ViewBox});
// 导入全局组件：结束


import router from './router.js'
import store from './store.js'
import App from ':views/App'



/* eslint-disable no-new */
var app = new Vue({
  el: '#app-box',
  router,
  store,
  components: {App},
  template: '<App/>',
  beforeDestroy: function () {
    store.saveState();
  }
});

by.defineListenableProperty(window.shareInst,"app",{
    getDefault:function () {return app}
});
window.shareInst.app = app;

// vue模块：结束




//mark:PWA配置
if (process.env.PWA && 'serviceWorker' in navigator) {
  window.byAddEventListener('load', function () {
    navigator.serviceWorker.register(`${__webpack_public_path__}service-worker.js`).then(registration => {
      console.log('ServiceWorker 注册成功: ', registration);
    }).catch(registrationError => {
      console.log('ServiceWorker 注册失败: ', registrationError);
    });
  });
}
